
$().ready(function() {
    $('.reg-left input').customInput();
});



    $('#xt_reg1').bind('click',function(){
        $('.xt_reg1_rgn').css('display','block');
        $('.xt_reg2_rgn').css('display','none');
        $(this).addClass('curr');
        $('#xt_reg2').removeClass('curr');

    });
    $('#xt_reg2').bind('click',function(){
        $('.xt_reg1_rgn').css('display','none');
        $('.xt_reg2_rgn').css('display','block');
        $('#xt_reg1').removeClass('curr');
        $(this).addClass('curr');
    });
    $("#mobile").bind('focus',function(){
    	$(".reg-user").children(".no").css("display","none");
    	$("#J_result_info").html('');
    });

    $('#getCode').bind('click', function(){
    	//验证手机号是否输入正确
    	var mobile = $("#mobile").val();
    	if($.trim($("#mobile").val())=="")
		{
    		$(".reg-user").children(".no").text("手机不能为空");
    		$(".reg-user").children(".no").css("display","inline");
			return false;
		}
		if($.trim($("#mobile").val())!="")
		{
			var reg = /^1[3|4|5|8][0-9]\d{4,8}$/;
			if(!reg.test($.trim($('#mobile').val())))
			{
				$(".reg-user").children(".no").text("请输入正确的手机号");
	    		$(".reg-user").children(".no").css("display","inline");
				return false;
			}
		}
    	
        //倒计时
        var wait=60;
        function time(o) {
            if (wait == 0) {
                o.removeAttribute("disabled");            
                o.value=" 获取验证码 ";
                wait = 60;
            } else {
                o.setAttribute("disabled", true);
                o.value=" 重新发送(" + wait + ") ";
                wait--;
                setTimeout(function() {
                    time(o);
                },
                1000);
            }
        }
        time(this);
   
        $.ajax({ type:"POST",
            dataType: "json",
            url: "/user/check/forgetcode", 
            data:{
                'mobile':$("#mobile").val(),
            },
            success: function(res){
                if(res.code !=200){
                	$("#getCode").val("获取验证码");
                	wait = 0;
                    $('#J_result_info').html(res.data.error);
                }
            }
        });


    });

    
    $(function(){
    	$(".forget_password").click(function(){
    		//验证手机号
    		if($.trim($("#mobile").val())=="")
    		{
        		$(".reg-user").children(".no").text("手机不能为空");
        		$(".reg-user").children(".no").css("display","inline");
    			return false;
    		}
    		if($.trim($("#mobile").val())!="")
    		{
    			var reg = /^1[3|4|5|8][0-9]\d{4,8}$/;
    			if(!reg.test($.trim($('#mobile').val())))
    			{
    				$(".reg-user").children(".no").text("请输入正确的手机号");
    	    		$(".reg-user").children(".no").css("display","inline");
    				return false;
    			}
    		}
    		//验证验证码
    		var code_phone = $.trim($("#code_phone").val());
    		if(code_phone == '' || code_phone == undefined || code_phone == null)
    		{
    			$('#J_result_info').html('请输入验证码');
    			return false;
    		}
    		//验证新密码
    		var password_phone = $.trim($("#password_phone").val());
    		if(password_phone == '' || password_phone == undefined || password_phone == null)
    		{
    			$('.password_phone_error').html('请输入新密码');
    			$('.password_phone_error').show();
    			return false;
    		}
    		if(password_phone.length < 6)
    		{
    			$('.password_phone_error').html('登录密码不能少于 6 个字符');
    			$('.password_phone_error').show();
    			return false;
    		}
    		//验证确认密码
    		var repassword_phone = $.trim($("#repassword_phone").val());
    		if(repassword_phone == '' || repassword_phone == undefined || repassword_phone == null)
    		{
    			$('.repassword_phone_error').html('请输入确定密码');
    			$('.repassword_phone_error').show();
    			return false;
    		}
    		if(repassword_phone != password_phone)
    		{
    			$('.repassword_phone_error').html('两次密码输入不一致');
    			$('.repassword_phone_error').show();
    			return false;
    		}
    		$.ajax({ type:"POST",
                dataType: "json",
                url: "/user/register/forget", 
                data:{
                    'mobile':$("#mobile").val(),
                    'code_phone':code_phone,
                    'password_phone':password_phone,
                    'repassword_phone':repassword_phone
                },
                success: function(res){
                    if(res.code !=200){
                    	$("#getCode").val("获取验证码");
                    	wait = 0;
                        $('#J_result_info').html(res.data.error_messages);
                    }
                    else
                    {
                    	alert('修改成功，请登录');
                    	window.location.href='/user/login';
                    }
                }
            });
    	});
    });